Passed
Pull Request — master (#45)
by
unknown
06:19
created

tab.js ➔ _interopDefaultLegacy   B

Complexity

Conditions 7

Size

Total Lines 1
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 1
dl 0
loc 1
rs 8
c 0
b 0
f 0
1
/*!
2
  * Bootstrap tab.js v4.5.3 (https://getbootstrap.com/)
3
  * Copyright 2011-2020 The Bootstrap Authors (https://github.com/twbs/bootstrap/graphs/contributors)
4
  * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
5
  */
6 View Code Duplication
(function (global, factory) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
7
  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('jquery'), require('./util.js')) :
8
  typeof define === 'function' && define.amd ? define(['jquery', './util.js'], factory) :
0 ignored issues
show
Bug introduced by
The variable define seems to be never declared. If this is a global, consider adding a /** global: define */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
9
  (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Tab = factory(global.jQuery, global.Util));
0 ignored issues
show
Best Practice introduced by
If you intend to check if the variable self is declared in the current environment, consider using typeof self === "undefined" instead. This is safe if the variable is not actually declared.
Loading history...
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
Bug introduced by
The variable globalThis seems to be never declared. If this is a global, consider adding a /** global: globalThis */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
10
}(this, (function ($, Util) { 'use strict';
11
12
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
13
14
  var $__default = /*#__PURE__*/_interopDefaultLegacy($);
15
  var Util__default = /*#__PURE__*/_interopDefaultLegacy(Util);
16
17
  function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
18
19
  function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
20
  /**
21
   * ------------------------------------------------------------------------
22
   * Constants
23
   * ------------------------------------------------------------------------
24
   */
25
26
  var NAME = 'tab';
27
  var VERSION = '4.5.3';
28
  var DATA_KEY = 'bs.tab';
29
  var EVENT_KEY = "." + DATA_KEY;
30
  var DATA_API_KEY = '.data-api';
31
  var JQUERY_NO_CONFLICT = $__default['default'].fn[NAME];
32
  var EVENT_HIDE = "hide" + EVENT_KEY;
33
  var EVENT_HIDDEN = "hidden" + EVENT_KEY;
34
  var EVENT_SHOW = "show" + EVENT_KEY;
35
  var EVENT_SHOWN = "shown" + EVENT_KEY;
36
  var EVENT_CLICK_DATA_API = "click" + EVENT_KEY + DATA_API_KEY;
37
  var CLASS_NAME_DROPDOWN_MENU = 'dropdown-menu';
38
  var CLASS_NAME_ACTIVE = 'active';
39
  var CLASS_NAME_DISABLED = 'disabled';
40
  var CLASS_NAME_FADE = 'fade';
41
  var CLASS_NAME_SHOW = 'show';
42
  var SELECTOR_DROPDOWN = '.dropdown';
43
  var SELECTOR_NAV_LIST_GROUP = '.nav, .list-group';
44
  var SELECTOR_ACTIVE = '.active';
45
  var SELECTOR_ACTIVE_UL = '> li > .active';
46
  var SELECTOR_DATA_TOGGLE = '[data-toggle="tab"], [data-toggle="pill"], [data-toggle="list"]';
47
  var SELECTOR_DROPDOWN_TOGGLE = '.dropdown-toggle';
48
  var SELECTOR_DROPDOWN_ACTIVE_CHILD = '> .dropdown-menu .active';
49
  /**
50
   * ------------------------------------------------------------------------
51
   * Class Definition
52
   * ------------------------------------------------------------------------
53
   */
54
55
  var Tab = /*#__PURE__*/function () {
56
    function Tab(element) {
57
      this._element = element;
58
    } // Getters
59
60
61
    var _proto = Tab.prototype;
62
63
    // Public
64
    _proto.show = function show() {
65
      var _this = this;
66
67
      if (this._element.parentNode && this._element.parentNode.nodeType === Node.ELEMENT_NODE && $__default['default'](this._element).hasClass(CLASS_NAME_ACTIVE) || $__default['default'](this._element).hasClass(CLASS_NAME_DISABLED)) {
0 ignored issues
show
Bug introduced by
The variable Node seems to be never declared. If this is a global, consider adding a /** global: Node */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
68
        return;
69
      }
70
71
      var target;
72
      var previous;
73
      var listElement = $__default['default'](this._element).closest(SELECTOR_NAV_LIST_GROUP)[0];
74
      var selector = Util__default['default'].getSelectorFromElement(this._element);
75
76
      if (listElement) {
77
        var itemSelector = listElement.nodeName === 'UL' || listElement.nodeName === 'OL' ? SELECTOR_ACTIVE_UL : SELECTOR_ACTIVE;
78
        previous = $__default['default'].makeArray($__default['default'](listElement).find(itemSelector));
79
        previous = previous[previous.length - 1];
80
      }
81
82
      var hideEvent = $__default['default'].Event(EVENT_HIDE, {
83
        relatedTarget: this._element
84
      });
85
      var showEvent = $__default['default'].Event(EVENT_SHOW, {
86
        relatedTarget: previous
0 ignored issues
show
Bug introduced by
The variable previous does not seem to be initialized in case listElement on line 76 is false. Are you sure this can never be the case?
Loading history...
87
      });
88
89
      if (previous) {
90
        $__default['default'](previous).trigger(hideEvent);
91
      }
92
93
      $__default['default'](this._element).trigger(showEvent);
94
95
      if (showEvent.isDefaultPrevented() || hideEvent.isDefaultPrevented()) {
96
        return;
97
      }
98
99
      if (selector) {
100
        target = document.querySelector(selector);
101
      }
102
103
      this._activate(this._element, listElement);
104
105
      var complete = function complete() {
106
        var hiddenEvent = $__default['default'].Event(EVENT_HIDDEN, {
107
          relatedTarget: _this._element
108
        });
109
        var shownEvent = $__default['default'].Event(EVENT_SHOWN, {
110
          relatedTarget: previous
0 ignored issues
show
Bug introduced by
The variable previous does not seem to be initialized in case listElement on line 76 is false. Are you sure this can never be the case?
Loading history...
111
        });
112
        $__default['default'](previous).trigger(hiddenEvent);
113
        $__default['default'](_this._element).trigger(shownEvent);
114
      };
115
116
      if (target) {
117
        this._activate(target, target.parentNode, complete);
118
      } else {
119
        complete();
120
      }
121
    };
122
123
    _proto.dispose = function dispose() {
124
      $__default['default'].removeData(this._element, DATA_KEY);
125
      this._element = null;
126
    } // Private
127
    ;
128
129
    _proto._activate = function _activate(element, container, callback) {
130
      var _this2 = this;
131
132
      var activeElements = container && (container.nodeName === 'UL' || container.nodeName === 'OL') ? $__default['default'](container).find(SELECTOR_ACTIVE_UL) : $__default['default'](container).children(SELECTOR_ACTIVE);
133
      var active = activeElements[0];
134
      var isTransitioning = callback && active && $__default['default'](active).hasClass(CLASS_NAME_FADE);
135
136
      var complete = function complete() {
137
        return _this2._transitionComplete(element, active, callback);
138
      };
139
140
      if (active && isTransitioning) {
141
        var transitionDuration = Util__default['default'].getTransitionDurationFromElement(active);
142
        $__default['default'](active).removeClass(CLASS_NAME_SHOW).one(Util__default['default'].TRANSITION_END, complete).emulateTransitionEnd(transitionDuration);
143
      } else {
144
        complete();
145
      }
146
    };
147
148
    _proto._transitionComplete = function _transitionComplete(element, active, callback) {
149
      if (active) {
150
        $__default['default'](active).removeClass(CLASS_NAME_ACTIVE);
151
        var dropdownChild = $__default['default'](active.parentNode).find(SELECTOR_DROPDOWN_ACTIVE_CHILD)[0];
152
153
        if (dropdownChild) {
154
          $__default['default'](dropdownChild).removeClass(CLASS_NAME_ACTIVE);
155
        }
156
157
        if (active.getAttribute('role') === 'tab') {
158
          active.setAttribute('aria-selected', false);
159
        }
160
      }
161
162
      $__default['default'](element).addClass(CLASS_NAME_ACTIVE);
163
164
      if (element.getAttribute('role') === 'tab') {
165
        element.setAttribute('aria-selected', true);
166
      }
167
168
      Util__default['default'].reflow(element);
169
170
      if (element.classList.contains(CLASS_NAME_FADE)) {
171
        element.classList.add(CLASS_NAME_SHOW);
172
      }
173
174
      if (element.parentNode && $__default['default'](element.parentNode).hasClass(CLASS_NAME_DROPDOWN_MENU)) {
175
        var dropdownElement = $__default['default'](element).closest(SELECTOR_DROPDOWN)[0];
176
177
        if (dropdownElement) {
178
          var dropdownToggleList = [].slice.call(dropdownElement.querySelectorAll(SELECTOR_DROPDOWN_TOGGLE));
179
          $__default['default'](dropdownToggleList).addClass(CLASS_NAME_ACTIVE);
180
        }
181
182
        element.setAttribute('aria-expanded', true);
183
      }
184
185
      if (callback) {
186
        callback();
187
      }
188
    } // Static
189
    ;
190
191
    Tab._jQueryInterface = function _jQueryInterface(config) {
192
      return this.each(function () {
193
        var $this = $__default['default'](this);
194
        var data = $this.data(DATA_KEY);
195
196
        if (!data) {
197
          data = new Tab(this);
198
          $this.data(DATA_KEY, data);
199
        }
200
201
        if (typeof config === 'string') {
202
          if (typeof data[config] === 'undefined') {
203
            throw new TypeError("No method named \"" + config + "\"");
204
          }
205
206
          data[config]();
207
        }
208
      });
209
    };
210
211
    _createClass(Tab, null, [{
212
      key: "VERSION",
213
      get: function get() {
214
        return VERSION;
215
      }
216
    }]);
217
218
    return Tab;
219
  }();
220
  /**
221
   * ------------------------------------------------------------------------
222
   * Data Api implementation
223
   * ------------------------------------------------------------------------
224
   */
225
226
227
  $__default['default'](document).on(EVENT_CLICK_DATA_API, SELECTOR_DATA_TOGGLE, function (event) {
228
    event.preventDefault();
229
230
    Tab._jQueryInterface.call($__default['default'](this), 'show');
231
  });
232
  /**
233
   * ------------------------------------------------------------------------
234
   * jQuery
235
   * ------------------------------------------------------------------------
236
   */
237
238
  $__default['default'].fn[NAME] = Tab._jQueryInterface;
239
  $__default['default'].fn[NAME].Constructor = Tab;
240
241
  $__default['default'].fn[NAME].noConflict = function () {
242
    $__default['default'].fn[NAME] = JQUERY_NO_CONFLICT;
243
    return Tab._jQueryInterface;
244
  };
245
246
  return Tab;
247
248
})));
249
//# sourceMappingURL=tab.js.map
250